/**
* signin-openid.js - Login functions for OpenID signin
*
* @version 2008-06-15
*/

/*---------------------------------------*/

function provider(u, s, l) {
  this.url = u;
  this.start = s;
  this.length = l;
}

var table = new Object;
table['0'] = new provider('http://www.yahoo.com/', 0, 0);
table['1'] = new provider('http://openid.aol.com/username', 22, 8);
table['2'] = new provider('http://username.livejournal.com/', 7, 8);
table['3'] = new provider('http://username.blogspot.com/', 7, 8);
table['4'] = new provider('http://username.myopenid.com/', 7, 8);
table['5'] = new provider('http://technorati.com/people/technorati/username', 40, 8);
table['6'] = new provider('http://username.pip.verisignlabs.com/', 7, 8);
table['7'] = new provider('http://claimid.com/username', 19, 8);
table['8'] = new provider('http://username.myvidoop.com/', 7, 8);
table['9'] = new provider('http://username.vox.com/', 7, 8);
table['10'] = new provider('http://username.wordpress.com/', 7, 8);

/**
* Onload events - executed when the page has load.
*/
window.onload=function()
{
    if(document.getElementById && document.createTextNode && document.createElement && document.getElementsByTagName) {
		$('standardform').onsubmit = function() { return showThrobber(); };


		var inputs = document.getElementsByTagName('input');
		for(var i=0;i<inputs.length;i++) {
			if(inputs[i].value.length < 1) {
				inputs[i].focus();
				break;
			}
		}

		var logos = document.getElementById('openidlogos').getElementsByTagName('a');
		for(var i=0;i<logos.length;i++) {
			if(logos[i].getAttribute('class') != 'direct' && logos[i].getAttribute('className') != 'direct') {
				logos[i].onclick = function() { setOpenID(this); return false; };
			}
		}

	}	
}

function showThrobber() {
 	$('waitimg').style.cssText = "position: relative; top: -28px; left: 13px; display: inline;";
	return true;
}

function setOpenID(o) {
	var type = o.href.substr(o.href.lastIndexOf('=')+1);
	var field = document.getElementById('openid_url');
	
	if ( typeof( table[type] ) != 'undefined' )
	{
		field.value = table[type].url;
		
		var start = table[type].start;
		var end   = table[type].start+table[type].length;
		if(field.setSelectionRange) {
			field.setSelectionRange(start,end);
		}
		else if (field.createTextRange) {
			var range = field.createTextRange();
			range.collapse(true);
			range.moveEnd('character', end);
			range.moveStart('character', start);
			range.select();
		}
	}
	field.focus();
}